/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lestr.udm.core.impl.types;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;
import org.lestr.udm.core.api.IDataType;
import org.lestr.udm.core.util.BasicDataTypes;

/**
 *
 * @author pibonnin
 */
public class NumberDataType implements IDataType {


    public static IDataType instance = new NumberDataType();


    @Override
    public String getId() {
        return "number";
    }


    @Override
    public IDataType getParentType() {
        return BasicDataTypes.NUMBER;
    }


    @Override
    public Object readValue(InputStream stream) {
        return new Scanner(stream).nextDouble();
    }


    @Override
    public InputStream writeValue(Object value) {
        
        ByteArrayOutputStream sortie = new ByteArrayOutputStream();
        
        PrintStream p = new PrintStream(sortie);
        p.print((Double) value);
        p.close();
        
        return new ByteArrayInputStream(sortie.toByteArray());
        
    }


}

